package web;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.DBCon;

/**
 * Servlet implementation class ServletCreateUserData
 */
@WebServlet({ "/ServletCreateUserData", "/Manager/UserData" })
public class ServletCreateUserData extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//生成User表测试集
		String sql;
		int Age;
		String TeaNum;
		String[] UserNum=new String[50]; //50个教师账号
		String sql_findDepName;
		
		ResultSet rs;
		Random rd=new Random();
		String MD5_Pwd="e10adc3949ba59abbe56e057f20f883e";

		try {
			//teacher表的数据插入操作
			sql_findDepName="Select TeaId From teacher";
			rs=new DBCon().find(sql_findDepName);
			int i=0;
			while(rs.next()) {
				UserNum[i]=rs.getString("TeaId");
				i++;
			}
			//获取到了全部教师账号
			//写循环
			//生成User表测试集		
			for(i=0;i<50;i++) {
				String Num=UserNum[i];
					sql= "insert into user values('"+Num+"','"+MD5_Pwd+"','教师')";
					int ret;
					ret=new DBCon().query(sql);
					System.out.println("ret="+ret);
				
			}
		}catch (ClassNotFoundException | SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
